﻿#include "btnform.h"
#include "ui_btnform.h"

btnForm::btnForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::btnForm)
{
    ui->setupUi(this);
    ui->modifyBtn->setStyleSheet("QPushButton#modifyBtn{border-image: url(:/pic/modify.png);}"
                                 "QPushButton#modifyBtn:hover{border-image: url(:/pic/modify2.png);}"
                                 "QPushButton#modifyBtn:pressed{border-image: url(:/pic/modify3.png);}");
    ui->deleteBtn->setStyleSheet("QPushButton#deleteBtn{border-image: url(:/pic/delete.png);}"
                                 "QPushButton#deleteBtn:hover{border-image: url(:/pic/delete2.png);}"
                                 "QPushButton#deleteBtn:pressed{border-image: url(:/pic/delete3.png);}");

}

btnForm::~btnForm()
{
    delete ui;
}

void btnForm::on_modifyBtn_clicked()
{
//    MainWindow* mw = new MainWindow;
//    connect(this, &btnForm::sendRowModify, mw, &MainWindow::getModify);
    if(index == 0)
        emit sendRowModify(rowIndexModify);
    else if(index == 1)
        emit sendGoodRowModify(rowIndexModifyGood);
//    disconnect(this, &btnForm::sendRowModify, mw, &MainWindow::getModify);
}

void btnForm::on_deleteBtn_clicked()
{
//    MainWindow* mw = new MainWindow;
//    connect(this, &btnForm::sendRowDelete, mw, &MainWindow::getDelete);
    if(index == 0)
        emit sendRowDelete(rowIndexDelete);
    else if(index == 1)
        emit sendGoodRowDelete(rowIndexDeleteGood);
//    disconnect(this, &btnForm::sendRowDelete, mw, &MainWindow::getDelete);
}

void btnForm::getRowModify(const int& index, const int& row)
{
    this->rowIndexModify = row;
    this->index = index;
}

void btnForm::getRowDelete(const int& index, const int& row)
{
    this->rowIndexDelete = row;
    this->index = index;
}

void btnForm::getGoodRowModify(const int& index, const int& row)
{
    this->rowIndexModifyGood = row;
    this->index = index;
}

void btnForm::getGoodRowDelete(const int& index, const int& row)
{
    this->rowIndexDeleteGood = row;
    this->index = index;
}
